# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>
# Contributor: Alexey Pavlov <alexpux@gmail.com>

_realname=pyqt-builder
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.18.1
pkgrel=1
pkgdesc="The PEP 517 compliant PyQt build system (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/Python-PyQt/PyQt-builder"
msys2_documentation_url="https://pyqt-builder.readthedocs.io"
msys2_references=(
  'purl: pkg:pypi/pyqt-builder'
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-sip")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
options=(!strip)
source=("https://pypi.io/packages/source/P/PyQt-builder/pyqt_builder-${pkgver}.tar.gz"
        001-mingw-python.patch)
sha256sums=('3f7a3a2715947a293a97530a76fd59f1309fcb8e57a5830f45c79fe7249b3998'
            'f373ea9e84c0340a425ba795b2a3eacabf1e5ec289c13661ba6d34ff373dffb8')

prepare() {
  cd ${_realname/-/_}-${pkgver}
  patch -p1 -i "${srcdir}/001-mingw-python.patch"

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd python-build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  # Delete bundled MSVC DLLs
  rm -rf "${pkgdir}"/${MINGW_PREFIX}/lib/python*/site-packages/pyqtbuild/bundle/dlls
}
